<!-- S search -->
<app-search-bar
  [submitLoading]="tableParams.loading"
  [searchOptions]="searchOptions"
  labelFlex="80px"
  (onSearch)="queryData($event)"
  (onReset)="resetData($event)"
>
</app-search-bar>
<!-- E search -->

<nz-card class="m-t-4">
  <div class="pagination-wrap-position p-t-10">
    <nz-table
      #basicTable
      nzSize="small"
      nzShowSizeChanger
      nzShowQuickJumper
      nzOuterBordered
      [nzScroll]="{ x: '1100px' }"
      [nzFrontPagination]="false"
      [nzLoadingDelay]="100"
      [nzLoading]="tableParams.loading"
      [nzData]="tableParams.tableData"
      [nzPageSizeOptions]="[5, 10, 20, 50, 100]"
      [nzTotal]="tableParams.total"
      [nzPageIndex]="tableParams.page"
      [nzPageSize]="tableParams.pageSize"
      [nzShowTotal]="totalTemplate"
      (nzPageIndexChange)="onPageIndexChange($event)"
      (nzPageSizeChange)="onPageSizeChange($event)"
      (nzCurrentPageDataChange)="onCurrentPageDataChange($event)"
    >
      <thead>
        <tr>
          <th
            nzWidth="50px"
            [(nzChecked)]="checked"
            [nzIndeterminate]="indeterminate"
            (nzCheckedChange)="onAllChecked($event)"
          ></th>
          <th nzAlign="center" nzWidth="200px" nzLeft>调拨单号</th>
          <th nzAlign="center" nzWidth="120px">调拨类型</th>
          <th nzAlign="center" nzWidth="120px">状态</th>
          <th nzAlign="center" nzWidth="120px">出库仓库</th>
          <th nzAlign="center" nzWidth="120px">入库仓库</th>
          <th nzAlign="center" nzWidth="150px">要求调拨</th>
          <th nzAlign="center" nzWidth="150px">实际调拨</th>
          <th nzAlign="center" nzWidth="170px">新建时间</th>
          <th nzAlign="center" nzWidth="280px" nzRight>操作</th>
        </tr>
      </thead>

      <tbody>
        <tr *ngFor="let data of basicTable.data; let index = index;">
          <td
            [nzChecked]="setOfCheckedId.has(data.id)"
            (nzCheckedChange)="onItemChecked(data.id, $event)"
          ></td>
          <!-- 调拨单号 -->
          <td nzAlign="center" nzLeft>
            <a
              style="color: #409EFF;"
              (click)="jumpPage(data)">
              {{ data.allocationNumber || '-' }}
            </a>
          </td>
          <!-- 调拨类型 -->
          <td nzAlign="center">
            {{ filterText(allocationTypeOptions, data.type, 'content') }}
          </td>
          <!-- 状态 -->
          <td nzAlign="center">
            <span [ngStyle]="{'color': data.state | storageAllocationState: 'color'}">
              {{ data.state | storageAllocationState: 'label' }}
            </span>
          </td>
          <!-- 出库仓库 -->
          <td nzAlign="center">
            {{ filterText(storeOptions, data.deliveryWhId, 'id') }}
          </td>
          <!-- 入库仓库 -->
          <td nzAlign="center">
            {{ filterText(storeOptions, data.warehousingWhId, 'id') }}
          </td>
          <!-- 要求调拨 -->
          <td nzAlign="center">
            <span [ngStyle]="{'color': data.allocationContent !== data.actualAllocationContent ? '#E6A23C' : ''}">
              {{ data.allocationContent || '-' }}
            </span>
          </td>
          <!-- 实际调拨 -->
          <td nzAlign="center">
            <span [ngStyle]="{'color': data.allocationContent !== data.actualAllocationContent ? '#E6A23C' : ''}">
              {{ data.actualAllocationContent || '-' }}
            </span>
          </td>
          <!-- 新建时间 -->
          <td nzAlign="center">{{ data.createTime || '-' }}</td>
          <!-- 操作 -->
          <td nzAlign="center" nzRight>
            <button
              nz-button
              nzType="link"
              nzSize="small"
              (click)="jumpPage(data)"
            >查看</button>

            <!-- <button
              *ngIf="permission.userPermission.has('storageCt:allocation:opera') && data.state === 3"
              nz-button
              nzType="link"
              nzSize="small"
              nzDanger
              (click)="showEditDeliveryModal(data)"
            >出库完毕</button> -->

            <button
              *ngIf="data.state === 4"
              nz-button
              nzType="link"
              nzSize="small"
              nzDanger
              nz-popconfirm
              nzPopconfirmTitle="确认通知仓库进行入库操作?"
              (nzOnConfirm)="noticeWarehousStore(data)"
            >通知入库</button>

            <button
              nz-button
              nzType="link"
              nzSize="small"
              (click)="showFollowModal(data)"
            >跟进</button>
          </td>
        </tr>
      </tbody>
    </nz-table>

    <!-- 分页template -->
    <ng-template #totalTemplate let-total>共有 {{ total }} 条</ng-template>
  </div>
</nz-card>

<!-- S 跟进Component -->
<app-follow-up
  #followUpRef
  [initParams]="initParams"
  [ohterParams]="{ type: 0, sourceType: 99 }"
></app-follow-up>
<!-- E 跟进Component -->

<!-- S 完善出库信息 Modal -->
<nz-modal
  nzClassName="custom-model-wrap"
  [nzFooter]="null"
  [(nzVisible)]="isDeliveryVisible"
  [nzTitle]="'完善出库信息'"
  (nzOnCancel)="isDeliveryVisible = false">

  <div *nzModalContent>
    <div class="custom-model-body">
      <form nz-form [formGroup]="validateDeliveryForm">
        <nz-form-item>
          <nz-form-label [nzSpan]="5" nzRequired>运费承担</nz-form-label>
          <nz-form-control [nzSpan]="19" nzErrorTip="请选择运费承担!">
            <nz-radio-group formControlName="isFreight">
              <label nz-radio [nzValue]="0">我方承担</label>
              <label nz-radio [nzValue]="1">用户承担</label>
            </nz-radio-group>
          </nz-form-control>
        </nz-form-item>

        <nz-form-item>
          <nz-form-label [nzSpan]="5" nzRequired>配送方式</nz-form-label>
          <nz-form-control [nzSpan]="19" nzErrorTip="请选择配送方式!">
            <nz-radio-group class="radio-psfs-wrap" formControlName="deliveryMethod">
              <label
                *ngFor="let option of deliveryOptions"
                nz-radio
                [nzDisabled]="option.value === 1"
                [nzValue]="option.value"
              >{{ option.label }}</label>
            </nz-radio-group>
          </nz-form-control>
        </nz-form-item>

        <nz-form-item>
          <nz-form-label [nzSpan]="5">物流公司</nz-form-label>
          <nz-form-control [nzSpan]="19" nzErrorTip="请选择物流公司!">
            <nz-select
              nzShowSearch
              nzAllowClear
              nzPlaceHolder="请选择物流公司"
              formControlName="expressCode">
              <nz-option
                *ngFor="let option of logisticsOptions"
                [nzLabel]="option.name"
                [nzValue]="option.content"
              ></nz-option>
            </nz-select>
          </nz-form-control>
        </nz-form-item>

        <nz-form-item>
          <nz-form-label [nzSpan]="5">物流单号</nz-form-label>
          <nz-form-control [nzSpan]="19" nzErrorTip="请输入物流单号!">
            <input nz-input placeholder="请输入物流单号" formControlName="expressNo" />
          </nz-form-control>
        </nz-form-item>

        <nz-form-item>
          <nz-form-label [nzSpan]="5">运费</nz-form-label>
          <nz-form-control [nzSpan]="19" nzErrorTip="请输入运费!">
            <nz-input-number
              style="width: 50%;"
              [nzMin]="1"
              [nzMax]="99999"
              [nzStep]="1"
              nzPlaceHolder="请输入运费"
              formControlName="expressPrice"
            ></nz-input-number>
          </nz-form-control>
        </nz-form-item>

        <nz-form-item>
          <nz-form-label [nzSpan]="5">发货备注</nz-form-label>
          <nz-form-control [nzSpan]="19" nzErrorTip="请输入发货备注!">
            <nz-textarea-count [nzMaxCharacterCount]="200">
              <textarea
                rows="4"
                nz-input
                maxlength="200"
                placeholder="请输入发货备注"
                formControlName="deliverRemark"
              ></textarea>
            </nz-textarea-count>
          </nz-form-control>
        </nz-form-item>
      </form>
    </div>

    <div class="custom-model-foot">
      <div class="custom-foot-cont">
        <button nz-button nzType="default" (click)="isDeliveryVisible = false">取消</button>
        <button nz-button nzType="primary" (click)="subEditDeliveryData()">确定</button>
      </div>
    </div>
  </div>
</nz-modal>
<!-- E 完善出库信息 Modal -->